
package ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.SingleLayoutHelper;

import net.ck.hzq.R;

import java.util.ArrayList;
import java.util.List;

import ui.model.ProfitBean;


/**
 * 当日收益头部适配器
 * Created by chenjian on 19/2/27
 */
public class ProfitAdapter extends DelegateAdapter.Adapter<ProfitAdapter.ProfitVH> {

    private final Context mContext;
    private List<ProfitBean> mData;
    public int index=-1;

    public ProfitAdapter(Context context) {
        mContext = context;
        mData = new ArrayList<>();
    }

    public void setupData(List<ProfitBean> data) {
        mData.clear();
        if (data != null) {
            mData.addAll(data);
        }
        notifyDataSetChanged();
    }

    public List<ProfitBean> getData() {
        return mData;
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return new SingleLayoutHelper();
    }

    @NonNull
    @Override
    public ProfitVH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ProfitVH(LayoutInflater.from(mContext).inflate(R.layout.item_profit_top, viewGroup, false));
    }




    @Override
    public void onBindViewHolder(@NonNull ProfitVH holder, int position) {
        if (position < 0 || position >= mData.size()) {
            return;
        }
        ProfitBean bean = mData.get(position);
        holder.amount.setText(bean.getTotalAmount());
        holder.income.setText(bean.getDividedIncome());
        holder.reward.setText(bean.getActiveReward());
        holder.merchant.setText(bean.getActiveMerchant());
//        Date date = new Date(bean.pushDate);
//        java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.CHINA);
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class ProfitVH extends RecyclerView.ViewHolder {
        private TextView amount;
        private TextView income;
        private TextView reward;
        private TextView merchant;

        ProfitVH(@NonNull View itemView) {
            super(itemView);
            amount = itemView.findViewById(R.id.item_profit_total_amount);
            income = itemView.findViewById(R.id.item_profit_divided_income);
            reward = itemView.findViewById(R.id.item_profit_active_reward);
            merchant = itemView.findViewById(R.id.item_profit_active_merchant);
        }
    }
}
